
// Linux API
#include <fcntl.h>
// C API
#include <assert.h>
// owner
#include "SocketsOps.hpp"
#include "Acceptor.hpp"

namespace tulun
{
    // class EventLoop;
    // class Acceptor::
    // using NewConnectionCallback = std::function<void(int connfd, const InetAddress &)>;
    // NewConnectionCallback newConnectionCallback_;
    // tulun::Socket acceptSocket_;
    // bool listenning_;
    // EventLoop *loop_;
    // tulun::Channel acceptChannel_;
    //  int idleFd_;
    void Acceptor::handleRead()
    {
        acceptSocket_.accept();
    }

    Acceptor::Acceptor(EventLoop *loop, const InetAddress &listenAddr, bool reuseport)
        : loop_(loop),
          acceptSocket_(Sockets::createNonblockingOrDie()),
          acceptChannel_(loop, acceptSocket_.fd()),
          listenning_(false),
          idleFd_(::open("/dev/null", O_RDONLY | O_CLOEXEC))
    {
        assert(idleFd_ > 0);
        acceptSocket_.bindAddress(listenAddr);
        acceptChannel_.setReadCallback(std::bind(&Acceptor::handleRead, this));
    }
    Acceptor::~Acceptor();
    bool Acceptor::listenning() const;
    void Acceptor::listen();

} // namespace tulun